package com.neutech.maplestory.entity;
import com.neutech.maplestory.client.MapleStoryClient;
import com.neutech.maplestory.constant.Constant;
import com.neutech.maplestory.util.ImageUtil;
import java.awt.*;
/**
 * 弓箭类的创建
 */

public class Arrow extends AbstractMapleStoryObject{
    public  static Image[] imgs ={
            ImageUtil.getImage("hero_right_arrow"),
            ImageUtil.getImage("hero_left_arrow")
    };


    public Arrow(){
        this.speed = 30;
    }
    public Arrow(MapleStoryClient msc ,int x, int y, Direction dir ){
        this();
        this.msc = msc;
        this.live = true;
        this.x = x;
        this.y = y;
        this.dir = dir;

    }
    @Override
    public void draw(Graphics g) {
        if(!live){
            msc.arrows.remove(this);
            return;
        }

        switch (dir){
            case RIGHT:
                g.drawImage(imgs[0],x,y,null);
                break;
            case LEFT:
                g.drawImage(imgs[1],x,y,null);
                break;
            default:
                break;
        }
        move();

    }

    @Override
    public void move() {
        switch (dir){
            case RIGHT:
                this.x += speed;
                break;
            case LEFT:
                this.x -= speed;
                break;
            default:
                break;
        }
        outOfBound();
    }
    private void outOfBound(){
        if (this.x<-500||this.x> Constant.GAME_WIDTH+500){
            this.live=false;
        }
    }
}
